

<template>
  <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
      :immediate-check="false"
      :offset="500"
    >
      <slot></slot>
    </van-list>
  </van-pull-refresh>
</template>

<script>
export default {
  data() {
    return {
      isLoading: false,
      loading: false,
      finished: false,
    };
  },
  props: ["refreshfunc", "loaddata"],
  methods: {
    onLoad() {
      setTimeout(
        () => {
          this.loaddata(
            () => {
              this.loading = false;
              this.ShowToast("加载成功");
            },
            () => {
              this.finished = true;
              this.ShowToast("没有更多数据了");
            }
          );
        },
        1000
      );
    },
    onRefresh(){
        setTimeout(()=>{
            this.refreshfunc(()=>{
                this.isLoading=false;
                this.ShowToast('刷新成功')
            })
        },1000)
    }
  },
};
</script>
